from time import sleep
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys

# 准备好参数配置
opt = Options()
opt.add_argument("--headless")
opt.add_argument("--disable-gpu")  # 设置为不显示

# 创建浏览器对象
web = Chrome(options=opt)

# 打开一个网址
web.get('https://www.lagou.com/')

web.maximize_window()

web.find_element_by_xpath('//*[@id="changeCityBox"]/p[1]/a').click()

web.find_element_by_id('search_input').send_keys('python',Keys.ENTER)

sleep(3)
# 查找存放数据的位置，进行数据的提取
# 找到页面中存放数据的所有div
div_list = web.find_elements_by_xpath('//*[@id="jobList"]/div[1]/div')
for div in div_list:
    sleep(1)
    job_name = div.find_element_by_xpath('./div[1]/div[1]/div[1]/a').text
    job_salary = div.find_element_by_xpath('./div[1]/div[1]/div[2]/span').text
    company_name = div.find_element_by_xpath('./div[1]/div[2]/div[1]/a').text
    print(job_name,job_salary)


